<%@ page language="java" contentType="text/html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Internal Requirement Page</title>
<link rel="stylesheet" href="../../css/styles.css" type="text/css" />
<script type="text/javascript" src="js/datetimepicker.js"></script>
<script type="text/javascript" src="js/validation.js"></script>
</head>
<script type="text/javascript">
	  function showEnterForm(){
	      document.getElementById("enterDiv").style.display = "block";
	      document.getElementById("viewDiv").style.display = "none";
	  }
	   function showSearchForm(){
	      document.getElementById("enterDiv").style.display = "none";
	      document.getElementById("viewDiv").style.display = "block";
	  }
	  function setDisplay(){
	     var getDetailsField = document.getElementById("getDetailsField");
	     var saveDetailsField = document.getElementById("saveDetailsField");
	     if(getDetailsField != null){
	        showSearchForm();
	     }else if(saveDetailsField != null){
	       showEnterForm();
	     }
	  }
	 function validateFormOnSubmit(theForm) {
		var reason = "";
		
		reason += validateSelectDept(theForm.irDeptId);
		reason += validateSelectProduct(theForm.irRequirement);
		reason += validateQuantity(theForm.irQuantity);
		reason += validateDate(theForm.irRequiredDate);
		if (reason != "") {
	    alert("Some fields need correction:\n" + reason);
	    return false;
	  }
	 return true;
	}
	function validateFormOnSearch(theForm){
		var reason = "";
		
		reason +=validateSelectDept(theForm.irDeptName);
		if (reason !=""){
		alert("Error Message:\n" + reason);
		return false;
		}
		return true;
	}
</script>
<body onload="javascript:setDisplay();">
<div id="container">
<jsp:include page="/jsp/menu.jsp" />

	<div style="height:420px;">
  		<div class="path">
			<br><a href="home.htm"> Home </a>-&gt;
			<a> Account </a>-&gt;
			<a> Purchase </a>-&gt;
			<a href="internalRequirement.htm"> Internal Requirement </a>
  		</div>
  		<div id="leftDiv" style="margin-left: 10px;margin-top: 20px">
   			<b>Internal Requirement Details</b><br><br>
			<fieldset  style="height:105px; width:160px;background: #FFF;">
			<table cellpadding=20>
			<tr>
				<td>
					<a href="javascript:showSearchForm()">
	                   View Internal Requirement Details
					</a>
				</td>
			</tr>
			<tr>
				<td>
                 	<a href="javascript:showEnterForm()">
	                    Enter Internal Requirement Details
                 	</a>
				</td>
			</tr>
			</table>
			</fieldset>
  		</div>
	</div>
	<form:form method="POST" action="getInternalRequirement.htm" commandName="internalRequirementDetails" onsubmit="return validateFormOnSearch(this)">
		<div id="viewDiv" class="maininfo"  style="display: none">
			<div class="lable">
				Internal Requirement Details
			</div>
			<div id="searchForm">
				<table>
					<tr>
						<th>Select Department Name</th>
						<td>
							<b><form:select path="irDeptName">
	  							<form:option value="" label="--- Select ---"/>
	  							<c:forEach items="${model.dList}" var="dept">
	  								<form:option value="${dept.numDeptId}">${dept.strDeptName}</form:option>
	  							</c:forEach>
	  						</form:select></b>
						</td>
					</tr>
					<tr>
						<th></th>
						<td><input type="submit" value="Search" size=5></td>
					</tr>
				</table>
			</div>
			<c:if test="${!empty model.rList}">
			<div id="viewTable" >
	  			<table  cellpadding="10">
					<tr>
						<th> DepartmentId </th>
						<th> Request Date </th>
						<th> Required Date </th>
						<th> Requirement </th>
						<th> Quantity </th>
						<th> Status </th>
						<th> Comments </th>
					</tr>
					<c:forEach items="${model.rList}" var="internalRequirementFormList">
					<tr>
						<td><c:out value="${internalRequirementFormList.irDeptId}"></c:out></td>
						<td><c:out value="${internalRequirementFormList.irRequestDate}"></c:out></td>
						<td><c:out value="${internalRequirementFormList.irRequiredDate}"></c:out></td>
						<td><c:out value="${internalRequirementFormList.irRequirement}"></c:out></td>
						<td><c:out value="${internalRequirementFormList.irQuantity}"></c:out></td>
						<td><c:out value="${internalRequirementFormList.irStatus}"></c:out></td>
						<td><c:out value="${internalRequirementFormList.irComments}"></c:out></td>
					</tr>
					</c:forEach> 
				</table>
			</div>
			</c:if>
		</div>
	</form:form>
 	<form:form method="POST" action="saveInternalRequirement.htm" commandName="internalRequirementDetails" onsubmit="return validateFormOnSubmit(this)">
 	<div id="enterDiv" class="maininfo"  style="display: none">
 		<div class="lable">
			Enter Internal Requirement Details
			<c:if test="${model.isSave}" >
				<div id="result"> <c:out value="Submitted Successfully"></c:out></div>
			</c:if>
		</div>
			<table>
				<tr>
					<th> Department <span class="mand-star">* </span> </th>
					<td><b><form:select path="irDeptId">
  							<form:option value="" label="--- Select ---"/>
  							<c:forEach items="${model.dList}" var="dept">
  								<form:option value="${dept.numDeptId}">${dept.strDeptName}</form:option>
  								<!--<form:option value="${dept.strDeptName}">${dept.strDeptName}</form:option>-->
  							</c:forEach>
	  				</form:select></b></td>
				</tr>
				<tr>
					<th> Requirement <span class="mand-star">* </span> </th>
					<td><b><form:select path="irRequirement">
  							<form:option value="" label="--- Select ---"/>
  							<c:forEach items="${model.pList}" var="product">
  								<form:option value="${product.numProdTypeId}">${product.strProdTypeDesc}</form:option>
  							</c:forEach>
	  				</form:select></b>
	  				</td>
	  			</tr>
				<tr>
					<th> Quantity <span class="mand-star">* </span> </th>
					<td><form:input path="irQuantity" /></td>
				</tr>
				<tr>
					<th> Comments  </th>
					<td><form:textarea  path="irComments" rows="3" cols="45" /></td>
				</tr>
				<tr>
					<th> Required Date <span class="mand-star">* </span> </th>
					<td><form:input path="irRequiredDate" id="demo1"/><a href="javascript:NewCal('demo1','mmddyyyy',true,24)">
					<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
				</tr>
				<tr>
					<th></th>
					<td><input type=submit value="Submit" /></td>
				</tr>
			</table>
		</div>
	</form:form>
	<c:if test="${model.isGet}">
	   	<input id="getDetailsField" type="hidden" name="getDetailsField"/>  
	</c:if>
	<c:if test="${model.isSave}">
	   <input id="saveDetailsField" type="hidden" name="saveDetailsField"/>  
	</c:if>	
	<div id="footer">
	<jsp:include page="/jsp/footer.jsp" />
	</div>
</div>
</body>
</html>
